#include <bits/stdc++.h>
using namespace std;

//f[n]=f[n-1]+f[n-2]+f[n-3];
int main(void){
	int f[1000001];
	int g[1000001];
	int n;
	f[0]=1;
	f[1]=1;
	f[2]=2;
	g[0]=0;
	g[1]=1;
	g[2]=2;
	cin>>n;
	for(int i=3;i<=n;i++){
		f[i]=f[i-1]+f[i-2]+2*g[i-2];
		f[i]%=10000;
		g[i]=f[i-1]+g[i-1];
		g[i]%=10000;
	}
	cout<<f[n];
	return 0;
}
